home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / check_one_link < prev    next >
Encoding:
Korn shell script  |  1995-03-24  |  1.9 KB  |  72 lines

  1. #! /bin/ksh
  2. USAGE='USAGE: check_one_link FILE_PATH MOUNT_PATH MAP_TO_PATH
  3.    Check one link file.  It is only allowed to be a link to below
  4.    MOUNT_PATH if it is a link to the corresponding file and the
  5.    corresponding file is not a link.  Otherwise, replace the 
  6.    link with the mirror link, i.e. replace MOUNT_PATH with MAP_TO_PATH.
  7. '
  8. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  9.  
  10. # Set variables
  11.  
  12. # Process parameters
  13.  
  14.    if [ $# -ne 3 ]
  15.    then
  16.       echo "$USAGE" >&2
  17.       echo "Wrong number of arguments." >&2
  18.       exit 1
  19.    fi
  20.    FILE_PATH="$1"; shift
  21.    if [ ! -L "$FILE_PATH" ]
  22.    then
  23.       echo "$USAGE" >&2
  24.       echo "$FILE_PATH is not a link." >&2
  25.       exit 1
  26.    fi
  27.    MOUNT_PATH="$1"; shift
  28.    if [ ! -d "$MOUNT_PATH" ]
  29.    then
  30.       echo "$USAGE" >&2
  31.       echo "$MOUNT_PATH is not a directory." >&2
  32.       exit 1
  33.    fi
  34.    MAP_TO_PATH="$1"; shift
  35.    if [ ! -d "$MAP_TO_PATH" ]
  36.    then
  37.       echo "$USAGE" >&2
  38.       echo "$MAP_TO_PATH is not a directory." >&2
  39.       exit 1
  40.    fi
  41.  
  42.    LINK="$(ls -l "$FILE_PATH" 2> /dev/null | cut -c56-500 | sed -e 's/^.* //')"
  43.    if [ "$LINK" != "${LINK#$MOUNT_PATH}" ]
  44.    then
  45.       if [ "$MAP_TO_PATH" = "/" ]
  46.       then
  47.          USE_MAP_TO=""
  48.       else
  49.          USE_MAP_TO="$MAP_TO_PATH"
  50.       fi
  51.       EQUIV="${USE_MAP_TO}${LINK#$MOUNT_PATH}"
  52.       if [ ! -L "$LINK" -a "$EQUIV" = "$FILE_PATH" ]
  53.       then
  54.          # A link is allowed to point at an equivalent real file
  55.          exit 0
  56.       fi
  57.       if [ "$EQUIV" = "$FILE_PATH" ]
  58.       then
  59.      NEW_LINK="$(ls -l "$LINK" 2> /dev/null | cut -c56-500 \
  60.                    | sed -e 's/^.* //')"
  61.      if [ "$NEW_LINK" != "${NEW_LINK#$MOUNT_PATH}" ]
  62.      then
  63.         NEW_LINK="${USE_MAP_TO}${LINK#$MOUNT_PATH}"
  64.      fi
  65.      EQUIV="$NEW_LINK"
  66.       fi
  67.       # Replace the link with the equivalent mirror 
  68.       echo "check_links: Replace link at $FILE_PATH with $EQUIV"
  69.       replace_link "$FILE_PATH" "$EQUIV"
  70.    fi
  71.    exit 0
  72.